//******************************************************************
//******************************************************************
//**********          ANts Peer To Peer Sources        *************
//
// ANts P2P realizes a third generation P2P net. It protects your
// privacy while you are connected and makes you not trackable, hiding
// your identity (ip) and crypting everything you are sending/receiving
// from others.

// Copyright (C) 2004  Roberto Rossi

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

package ants.p2p.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.image.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class LabelIcon implements Icon{
  String label = null;
  Image icon = null;
  int width = 150;
  int height = 30;
  Component comp = null;

  public LabelIcon(String label, Image icon, Component c) {
    this.label = label;
    this.icon = icon;
    this.comp = c;
    Font f = UIManager.getFont("Panel.font");
    this.width = (int)Math.floor(c.getFontMetrics(f).getStringBounds(label,c.getGraphics()).getWidth()) + icon.getWidth(c) + 5;
    //this.height = icon.getHeight(c) + 2;
  }

  public int getIconHeight(){
    return height;
  }

  public int getIconWidth(){
    if((comp instanceof DownloadAntPanel || comp instanceof UploadAntPanel) &&
       this.width < 300)
      this.width = 300;
    return width;
  }

  public void paintIcon(Component c, Graphics g, int x, int y) {
    this.width = (int)Math.floor(g.getFontMetrics().getStringBounds(label,g).getWidth()) + icon.getWidth(c) + 5;
    //this.height = icon.getHeight(c) + 2;
    int factorY = (30 - icon.getHeight(comp))/2;
    g.drawImage(icon, x + 1, y + factorY, c);
    if(c.isEnabled())
      g.setColor(Color.black);
    else
      g.setColor(Color.gray);
    g.drawString(label, x + icon.getWidth(c) + 2, (int)(y + /*(icon.getHeight(c) + 2)*/30/2 /*+g.getFontMetrics().getStringBounds(label,g).getHeight()/2*/));
  }

}
